<?php
class SysattachAction extends BaseAction
{
	
	function upload(){
		$this->display();
	}
	
	public function uploading(){
		$Dao = D("Sysattach"); 
 		if(!empty($_FILES['file1']['name'])){
            //添加附件
            import("ORG.Net.UploadFile");
            $upload = new UploadFile();
            $upload->maxSize  = 32922000 ;
            $upload->allowExts  = explode(',','pdf,caj,rar,zip,doc,exl,txt,jpg,gif');
            $upload->savePath = './Public/file/';

            //执行上传操作
            $result = $upload->upload();
            if($result){
				$result = $upload->getUploadFileInfo();
				//dump($result);exit;
				$Dao->create($result[0]);
				$Dao->add();
			}
        }else{
			$this->assign('done','没有上传,请确认选择文件!');
		}

		$this->display();
	}

	function browse()
	{
		$map = "1=1 ";		
		$Dao = D("Sysattach"); 
		import("ORG.Util.Page"); 
		$listRows = 5; 

		$field = "*"; 
		$count = $Dao->count($map); 
		$p = new Page($count,$listRows); 
		$list = $Dao->findAll($map,$field,"id desc",$p->firstRow.",".$p->listRows); 
		$page = $p->show();
		 
		$this->assign("list",$list); 
		$this->assign("page",$page); 
	$this->root = D('Syssite')->getField("url","id=1");
		$this->display(); 
	}

	function index()
	{
		$map = "1=1 ";		
		$Dao = D("Sysattach"); 
		import("ORG.Util.Page"); 
		$listRows = 20; 

		$field = "*"; 
		$count = $Dao->count($map); 
		$p = new Page($count,$listRows); 
		$list = $Dao->findAll($map,$field,"id desc",$p->firstRow.",".$p->listRows); 
		$page = $p->show();
		 
		$this->assign("list",$list); 
		$this->assign("page",$page); 
	
		$this->display(); 
	}
	
	function add(){
		$this->display();
	}
	
	function up(){
		$this->display(); 
	}
	function uping(){
 		if(!empty($_FILES['file1']['name'])){
            //添加附件
            import("ORG.Net.UploadFile");
            $upload = new UploadFile();
            $upload->maxSize  = 32922000 ;
            $upload->allowExts  = explode(',','jpg,gif');
            $upload->savePath = './Public/file/';

            //执行上传操作
            $result = $upload->upload();
            if(!$result){
                $this->error("上传出错! ".$upload->getErrorMsg());
            }
            $result = $upload->getUploadFileInfo();
            $file =	$result[0]['savepath'].$result[0]['savename'];
            //dump($file);
			//dump($result[0]);
			$Dao = D("Sysattach"); 
			$vo = $Dao->create($result[0]); 
			if(false === $vo) { 
				$this->error($Dao->getError()); 
			} 
	 
			$rs = $Dao->add(); 
			if($rs){ 
				$this->assign("jumpUrl",__URL__."/index/nid/".$vo['nid']); 
				$this->success("添加数据成功!"); 
			}else{ 
				$this->error("添加数据失败"); 
			} 
			//include "./Include/sImage.class.php";
            //$img = new sImage();
            //$w=313;$h=216;
            //$file_s    = './Public/file/s_'.$result[0]['savename'];
            //$img->cutThumb($file,$file_s,$w,$h);			
            //$Dao->imgurl = $file_s;
			echo ('上次成功!'.$file_s);
        }else{
			echo ('上次失败!'.$file_s);
		}
		
	}
	
	function delete() 
	{ 
		// 根据id删除指定的记录
		$Dao = D("Sysattach"); 
		$id = $_REQUEST["id"];
        $num = $Dao->count();
        if($num<2) $this->error('请勿删除最后一个管理员帐号,否则无法登陆!');
		if(isset($id)) { 
			$result = $Dao->getById($id); 
			if(!$result) { 
				$this->error("Non-existed record!"); 
			} 
			unlink('./Public/file/'.$Dao->savename);
			if($Dao->deleteById($id)){ 
				$this->assign("jumpUrl",__URL__); 
				$this->success("删除数据成功"); 
			}else { 
				$this->error("删除数据失败"); 
			}
		}else { 
			$this->error("非法操作"); 
		} 
	}

	
	

}
?>